home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / BT_TOP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  1.8 KB  |  59 lines

  1. /*  bt_top.c - find_exact, find_ins, find_del functions */
  2. #include   "stdio.h"
  3. #include   "btree.h"
  4. #include   "bt_macro.h"
  5. extern    IX_DESC    *pci ;
  6.  
  7. int  find_exact(pe,pix)         /* find entry with same key & rptr */
  8.   ENTRY *pe ;                /* put the entry here */
  9.   IX_DESC  *pix ;            /* points to an index descriptor */
  10.   {
  11.      int   ret ;
  12.      ENTRY e ;
  13.  
  14.      pci = pix ;
  15.      copy_entry(&e,pe) ;        /* make copy for find call */
  16.      ret = find_ix(&e,pix) ;        /* get first entry that matches key */
  17.  
  18.      while( ret == 0 )            /* keep going until keys don't match */
  19.     {  if( e.rptr == pe->rptr )    /* compare rec. ptrs */
  20.           return( 0 ) ;        /* return if they match */
  21.                     /* ptrs not same - continue  */
  22.        if( get_next(&e,pix) == EOIX )    /* get next entry */
  23.           return( 1 ) ;        /* at end-of-index  not found */
  24.        ret = call(pci->pcomp) (&e,pe) ;    /* compare keys */
  25.     }
  26.      return( ret ) ;            /* not found - non-zero code */
  27.   }
  28.  
  29.  
  30. int  find_ins(pe,pix)            /* find position, insert an entry */
  31.   ENTRY *pe ;                /* the entry */
  32.   IX_DESC  *pix ;            /* points to an index descriptor */
  33.   {                    /* returns IX_FAIL if entry present */
  34.      int   ret ;
  35.      ENTRY tempe ;
  36.  
  37.      if(find_exact(pe,pix) == 0 )    /* look for the entry */
  38.     return( IX_FAIL ) ;        /* already there - failure */
  39.                     /* the find set the curr. pos */
  40.      return(insert_ix(pe,pix)) ;    /* do the insertion */
  41.   }
  42.  
  43. int  find_del(pe,pix)            /* find position, delete an entry */
  44.   ENTRY *pe ;                /* the entry */
  45.   IX_DESC  *pix ;            /* points to an index descriptor */
  46.   {                    /* returns IX_FAIL if not found */
  47.      int   ret ;
  48.      ENTRY tempe ;
  49.  
  50.      if(find_exact(pe,pix) != 0 )    /* look for the entry */
  51.     return( IX_FAIL ) ;        /* not there     - failure */
  52.                     /* the find set the curr. pos */
  53.      return(delete_ix(pe,pix)) ;    /* do the deletion */
  54.  
  55.   }
  56.  
  57.  
  58.  
  59.